package com.example.service.impl;

import com.example.mapper.EmpMapper;
import com.example.mapper.StudentMapper;
import com.example.pojo.ClazzCountOption;
import com.example.pojo.JobOtion;
import com.example.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 统计员工职位数据
     *
     * @return JobOtion
     */
    @Override
    public JobOtion getEmpJobData() {
        //1.获取统计数据
        List<Map<String, Object>> mapList = empMapper.countEmpJobData();

        //2.组装结果,并返回
        JobOtion jobOtion = new JobOtion();
        jobOtion.setJobList(mapList.stream().map(dataMap -> dataMap.get("position")).toList());
        jobOtion.setDataList(mapList.stream().map(dataMap -> dataMap.get("num")).toList());

        return jobOtion;
    }


    /**
     * 统计员工性别数据
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /**
     * 学员学历统计
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    /**
     * 班级人数统计
     */
    @Override
    public ClazzCountOption getStudentCountData() {
        //获取统计数据
        List<Map<String, Object>> mapList = studentMapper.countStudentCountData();

        //组装结果,并返回
        ClazzCountOption clazzCountOption = ClazzCountOption.builder()
                .clazzList(mapList.stream().map(dataMap -> dataMap.get("clazzName")).toList())
                .dataList(mapList.stream().map(dataMap -> dataMap.get("num")).toList())
                .build();

        return clazzCountOption;
    }

}
